import userApi,{ ILoginData, User } from "@/apis/userApi"
import { CacheEnum } from "@/enum/userEnum"
import store from "@/utils/store"
import { defineStore} from "pinia"

//pinia的state对应ref  actions对应methods(可以为异步方法)  getter对应计算属性
export default defineStore('user',{
    state:()=>{
        return {
             info:{} as any
        }
    },
    actions:{ //获取用户个人信息(异步请求方法)
       async getUserInfo(userName:string,password:string){
      if(store.get(CacheEnum.TOKEN_NAME)){
        this.info=  (await userApi.userInfo()).data
     
      }
       },

       async  userChecked(){
    return  (await userApi.checkToken()).msg
     
     
       }
    },
    persist:{
      key:'userInfo',
      storage:sessionStorage
 }
})